extern crate net_brd;
use net_brd::Color;
use net_brd::ChainData;
use net_brd::Chain;
use net_brd::excutive::CmdRun;
// use net_brd::output::OutputValue;
// use net_brd::output::WraperParser;
// use net_brd::log_utils;
fn main(){
    // log_utils::log_init();
    let _ = net_brd::ls_brd().iter().map(|x| x.chain_remove()).collect::<Vec<_>>();
    let b = "curl".with_cmd()
        .args(&vec!["https://www.douban.com"])
        .output(net_brd::OUTPUT_TO_LOG)
        .wraper("to_css", vec!["a[href]"])
        .wraper("to_re", vec![r#"http.+douban.+"#])
        .wraper("to_grep",vec!["tag"])
        .wraper("to_grep",vec!["book"])
        .new_chain();
    log::info!("{}",b);
    
    // let test_task_str = b.task.to_string();
    // b.run();
    log::info!("task : \n{}\n",b.task);
    let id = b.save();
    // let mut test_b = test_task_str.to_task().unwrap().new_chain();
    if let Some(mut test_b) = id.chain_load(){
        test_b.run();
        Chain::wait();
    log::info!("\n{}",test_b.task_path().file_open_str().unwrap().bold().blue());
    };
    
    // let task_path = b.task_path();
    // if let Some(buf) = task_path.file_open_str(){
        // log::info!("run {}", buf.len());
        // for i in buf.as_wraper().to_css("a[href]").to_re(r#"(http.+[^w]{3}\.douban\..+/)"#).to_vec(){
        //     log::info!("{}",i.yellow());
        // }

        // for json_str in buf.as_wraper().to_css("li | ").to_re(r#"<\w(.+?)(?:>)"#).to_json(" ", "=").to_vec(){
        //     log::info!("xml to json :{}", json_str.bold().green());
        // };
    // }
    
}